<template>
  <el-container class="home-container">
    <!-- 右侧内容主体 -->
    <el-header height="50px">
      <!-- 头部区 -->
      学生宿舍管理系统
      <el-button type="primary" @click="logout">退出登录</el-button>
    </el-header>
    <!-- 页面主体区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="200px">
        <el-menu background-color="#304156" text-color="#fff" :unique-opened="true" :collapse-transition="false"
          :router="true">
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-message"></i>
              <span slot="title" class="build_management">宿舍楼层信息管理</span>
            </template>

            <el-menu-item index="/builidinformation" active>宿舍楼宇管理</el-menu-item>
            <el-menu-item index="/dormitoryinformation">宿舍信息</el-menu-item>
            <!-- <el-menu-item index="/test">测试页面</el-menu-item> -->
          </el-submenu>

          <el-menu-item index="/stuinfo">
            <i class="el-icon-menu"></i>
            <span slot="title">宿舍学生信息管理</span>
          </el-menu-item>
          <el-menu-item index="/stuservice">
            <i class="el-icon-document"></i>
            <span slot="title">宿舍维修信息管理</span>
          </el-menu-item>
          <el-menu-item index="4">
            <i class="el-icon-setting"></i>
            <span slot="title">信息管理</span>
          </el-menu-item>
        </el-menu>

      </el-aside>
      <!-- 右侧内容主体 -->
      <el-main>
        <!-- 右侧内容主体 -->
        <el-main>
          <!-- 路由占位符 -->
          <router-view></router-view>
        </el-main>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>

export default {
  name: 'App',
  data() {
    return {
      activeIndex: "/NewReport",
    };
  },
  methods: {
    handleSelect() {
      // 路由跳转时，标记在导航的那个选项下对应的路由
      this.activeIndex = this.$route.path
    },
    logout() {
      window.sessionStorage.clear();
      this.$router.push({ path: "/" }),
        this.$message({
          showClose: true,
          message: '您已退出',
          type: 'success'
        });
    }
  },
  watch: {
    // 监听路由变化
    '$route.path': {
      handler(routePath) {
        this.handleSelect(routePath)
      }
    }
  },
}

</script>
<style lang="less" scoped>
.el-container {
  cursor: pointer;
  height: 100%;
  position: flex;
}

.home-container {
  height: 100%;
}

.el-header {
  background-color: #304156;
  display: flex; //设置显示为flex布局
  justify-content: space-between; //设置为flex左右布局
  padding-left: 20px; //左内边距为0（Logo贴左边）
  align-items: center; //元素上下居中（防止右边按钮贴上下边）
  color: #fff;
  font-size: 25px;

  >div {
    //内嵌的div样式
    display: flex;

    align-items: center; //Logo和文字上下居中

    span {
      margin-left: 15px; //文字左侧设置间距，防止与Logo紧贴
    }
  }
}

.el-button {
  margin-right: 20px;
}

.build_management {
  font-size: 16px;
}

.el-aside {
  background-color: #304156;
  width: 400px;
  height: 100%;
  float: left;
  font-size: 20px;
}

.el-submenu /deep/ .el-submenu__title {
  height: 50px;
  position: flex;
  background-color: #304156;
}


.el-menu-item {
  font-size: 16px;
  padding-bottom: 30px;
  padding-left: 0px;
}

.el-menu-item.is-active {
  color: #ffffff;
  background-color: #1f2d3d !important;
}

li {
  padding-left: -30px;
  list-style: none;
}

.el-menu {
  margin: 0;
  padding: 0;
}

.el-main {
  background-color: #e3e3e3;
  height: 100%;
}
</style>